package com.ttai.presenter.activity;

import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import android.widget.Toast;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.ttai.model.dao.DBHelper;
import com.ttai.model.dao.bean.Acount_Item;
import com.ttai.model.net.NewAcountBean;
import com.ttai.model.net.ResponseInfo;
import com.ttai.model.net.TipAcountBean;
import com.ttai.presenter.base.BasePresenter;
import com.ttai.ui.activity.AcountItem;
import com.ttai.ui.activity.EnterPage;
import com.ttai.ui.activity.UaP_Protect;
import com.ttai.ui.activity.VerifyLogin;
import com.ttai.ui.activity.VerifyMiYao;

import java.util.ArrayList;

import retrofit2.Call;

public class InsertNewAcountPresenter extends BasePresenter {
    UaP_Protect uaP_protect;
    VerifyLogin verifyLogin;
    VerifyMiYao verifyMiYao;

    public ArrayList<Acount_Item> getList() {
        return list;
    }

    private ArrayList<Acount_Item> list = new ArrayList<>();

    public NewAcountBean newAcountBean;

    public InsertNewAcountPresenter(UaP_Protect uaP_protect) {
        this.uaP_protect = uaP_protect;
    }

    @Override
    protected void showError(String message) {
    }

    @Override
    protected void parseJson(JsonObject json) {
        Gson gson = new Gson();
        newAcountBean = gson.fromJson(json,NewAcountBean.class);
            for (int i = 0; i < newAcountBean.getAccount().size(); i++) {
//                String phone = newAcountBean.getAccount().get(i).getTsAccount();
                String acountName = newAcountBean.getAccount().get(i).getAccountName();
                String imgUrl = newAcountBean.getAccount().get(i).getIcon();
                Acount_Item acount_item = new Acount_Item(acountName,imgUrl);
                list.add(acount_item);

                uaP_protect.getAdapter().setData(list);
//                DBHelper dbHelper = DBHelper.getInstance(enterPage);
//                SQLiteDatabase db=dbHelper.getWritableDatabase();
//                ContentValues values=new ContentValues();
//                values.put("phone",phone);
//                values.put("acountname",acountName);
//                values.put("imgurl",imgUrl);
//                values.put("acounttip","");
//                Log.i("newAcount", "parseJson: "+acountName+"img"+imgUrl);
//                db.insert("newacount",null,values);
//                values.clear();
            }
        }

//    public NewAcountBean getNewAcountBean() {
//        return newAcountBean;
//    }

    public void storeNewAcount(String token){
        Call<ResponseInfo> newAcountInfo = responseInfoApi.restoreNewAcount(token);
        newAcountInfo.enqueue(new CallBackAdapter());
    }

}
